import promiseFromWXCallback from '../lib/promiseFromWXCallback';

const request = promiseFromWXCallback(wx.request)
const host = 'https://www.qianyangwangluo.com:10010'
// const host = 'http://localhost:8800'

export default (config) => {
  try {
    const token = wx.getStorageSync('token')
    if (config.path && config.path.indexOf('http://') === 0) {
      config.url = config.path
    } else {
      config.url = config.path ? host + config.path : config.url
    }
    config.header = config.header || {}
    config.header.Authorization = 'Bearer ' + token
    return request(config)
  } catch (e) {
    console.log(e)
  }
}
